package org.nokatag.tagjava;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
/**
 * color select
 * @author rebin
 *
 */
public class ColorSelect extends Inputsuper{
	private static final long serialVersionUID = 7869498561857965838L;
	private String customcolors="true";
	private String selectonclick="true";
	
	public int doStartTag() throws JspException {
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		String basePath = basepath(request);
		JspWriter jspOut = pageContext.getOut();
		StringBuilder bodystr = new StringBuilder();
		bodystr.append(potjs(request));
		bodystr.append(ColorSelectJS(request));
		bodystr.append("<input type=\"text\" "+getBaseStr()+" ");
		if("true".equalsIgnoreCase(customcolors))
			bodystr.append("customcolors=\""+customcolors+"\"");
		if("true".equalsIgnoreCase(selectonclick))
			bodystr.append("selectonclick=\""+selectonclick+"\"");
		bodystr.append("/>");	
		bodystr.append("<script>");
		bodystr.append("Event.observe(document, 'dom:loaded', function() {");
		bodystr.append("var cfgs"+getId()+" = {");
		bodystr.append("id:'"+getId()+"',");
		bodystr.append("readonly:'"+(getReadonly()==null?"":getReadonly())+"',");//只读
		bodystr.append("disabled:'"+(getDisabled()==null?"":getDisabled())+"',");
		bodystr.append("rooturl:'"+basePath+"'");
		bodystr.append("};");
		bodystr.append(" var CP_"+getId()+" = new ncolorSelect(cfgs"+getId()+");");
		bodystr.append(" CP_"+getId()+".show();");
		bodystr.append("});");
		bodystr.append("</script>");
		try {
			jspOut.write(bodystr.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;
	}

	public String getCustomcolors() {
		return customcolors;
	}

	public void setCustomcolors(String customcolors) {
		this.customcolors = customcolors;
	}

	public String getSelectonclick() {
		return selectonclick;
	}

	public void setSelectonclick(String selectonclick) {
		this.selectonclick = selectonclick;
	}
}
